/**
 * @copyright 2018 sinping.com 北京芯平科技股份有限公司. All rights reserved.
 * 本内容仅限于北京芯平科技股份有限公司内部传阅，禁止外泄以及用于其他的商业目的.
 */
package com.sinping.qh.utils.base.type;

import com.sinping.qh.utils.base.ExceptionUtil;

/**
 *
 *
 * @author yuyue
 * @create 2018/5/25
 */
public class CloneableException extends Exception implements Cloneable {

    private static final long serialVersionUID = -6270471689928560417L;

    protected String message; //NOSONAR

    public CloneableException() {
        super((Throwable) null);
    }

    public CloneableException(String message) {
        super((Throwable) null);
        this.message = message;
    }

    public CloneableException(String message, Throwable cause) {
        super(cause);
        this.message = message;
    }

    @Override
    public CloneableException clone() { //NOSONAR
        try {
            return (CloneableException) super.clone();
        } catch (CloneNotSupportedException e) {// NOSONAR
            return null;
        }
    }

    @Override
    public String getMessage() {
        return message;
    }

    /**
     * 简便函数，定义静态异常时使用
     */
    public CloneableException setStackTrace(Class<?> throwClazz, String throwMethod) {
        ExceptionUtil.setStackTrace(this, throwClazz, throwMethod);
        return this;
    }

    /**
     * 简便函数, clone并重新设定Message
     */
    public CloneableException clone(String message) {
        CloneableException newException = this.clone();
        newException.setMessage(message);
        return newException;
    }

    /**
     * 简便函数, 重新设定Message
     */
    public CloneableException setMessage(String message) {
        this.message = message;
        return this;
    }
}